home *** CD-ROM | disk | FTP | other *** search
/ Aminet 50 / Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso / Aminet / util / wb / AmiStart.lha / ToolsSDK.lha / source / LibInit.c < prev    next >
C/C++ Source or Header  |  2002-06-01  |  6KB  |  181 lines

  1. /*
  2. **      $VER: LibInit.c 37.32 (2.3.99)
  3. **
  4. **      Library initializers and functions to be called by StartUp.c
  5. **
  6. **        modified by Darius Brewka orginal by
  7. **          (C) Copyright 1996-99 Andreas R. Kleinert
  8. **          All Rights Reserved.
  9. */
  10.  
  11. #define __USE_SYSBASE        // perhaps only recognized by SAS/C
  12.  
  13. #include <exec/types.h>
  14. #include <exec/memory.h>
  15. #include <exec/libraries.h>
  16. #include <exec/execbase.h>
  17. #include <exec/resident.h>
  18. #include <exec/initializers.h>
  19.  
  20. #ifdef __MAXON__
  21. #include <clib/exec_protos.h>
  22. #else
  23. #include <proto/exec.h>
  24. #endif
  25. #include "compiler.h"
  26.  
  27. #include "amistart_modulebase.h"
  28.  
  29. ULONG __saveds __stdargs L_OpenLibs(struct AmiStartModuleBase *AmiStartModuleBase);
  30. void  __saveds __stdargs L_CloseLibs(void);
  31.  
  32. struct ExecBase      *SysBase       = NULL;
  33. struct IntuitionBase *IntuitionBase = NULL;
  34. struct GfxBase       *GfxBase       = NULL;
  35. struct DosBase         *DOSBase        = NULL;
  36. //struct Library         *MUIMasterBase = NULL;
  37. struct Library       *UtilityBase   = NULL;
  38.  
  39.  
  40. #define VERSION  39
  41. #define REVISION 0
  42.  
  43. #define EXLIBNAME "showram"
  44. #define EXLIBVER  " 39.0 (15.03.02)"
  45.  
  46. char __aligned ExLibName [] = EXLIBNAME ".tool";
  47. char __aligned ExLibID   [] = EXLIBNAME EXLIBVER;
  48. char __aligned Copyright [] = "(c) by Darius Brewka";
  49.  
  50. char __aligned VERSTRING [] = "\0$VER: " EXLIBNAME EXLIBVER;
  51.  
  52. /* ----------------------------------------------------------------------------------------
  53.    ! ROMTag and Library inilitalization structure:
  54.    !
  55.    ! Below you find the ROMTag, which is the most important "magic" part of a library
  56.    ! (as for any other resident module). You should not need to modify any of the
  57.    ! structures directly, since all the data is referenced from constants from somewhere else.
  58.    !
  59.    ! You may place the ROMTag directly after the LibStart (-> StartUp.c) function as well.
  60.    !
  61.    ! Note, that the data initialization structure may be somewhat redundant - it's
  62.    ! for demonstration purposes.
  63.    !
  64.    ! EndResident can be placed somewhere else - but it must follow the ROMTag and
  65.    ! it must not be placed in a different SECTION.
  66.    ---------------------------------------------------------------------------------------- */
  67.  
  68. extern ULONG InitTab[];
  69. extern APTR EndResident; /* below */
  70.  
  71. struct Resident __aligned ROMTag =     /* do not change */
  72. {
  73.  RTC_MATCHWORD,
  74.  &ROMTag,
  75.  &EndResident,
  76.  RTF_AUTOINIT,
  77.  VERSION,
  78.  NT_LIBRARY,
  79.  0,
  80.  &ExLibName[0],
  81.  &ExLibID[0],
  82.  &InitTab[0]
  83. };
  84.  
  85. APTR EndResident;
  86.  
  87. struct MyDataInit                      /* do not change */
  88. {
  89.  UWORD ln_Type_Init;      UWORD ln_Type_Offset;      UWORD ln_Type_Content;
  90.  UBYTE ln_Name_Init;      UBYTE ln_Name_Offset;      ULONG ln_Name_Content;
  91.  UWORD lib_Flags_Init;    UWORD lib_Flags_Offset;    UWORD lib_Flags_Content;
  92.  UWORD lib_Version_Init;  UWORD lib_Version_Offset;  UWORD lib_Version_Content;
  93.  UWORD lib_Revision_Init; UWORD lib_Revision_Offset; UWORD lib_Revision_Content;
  94.  UBYTE lib_IdString_Init; UBYTE lib_IdString_Offset; ULONG lib_IdString_Content;
  95.  ULONG ENDMARK;
  96. } DataTab =
  97. #ifdef __VBCC__
  98. {
  99.         0xe000,8,NT_LIBRARY,
  100.         0x0080,10,(ULONG) &ExLibName[0],
  101.         0xe000,LIBF_SUMUSED|LIBF_CHANGED,
  102.         0xd000,20,VERSION,
  103.         0xd000,22,REVISION,
  104.         0x80,24,(ULONG) &ExLibID[0],
  105.         (ULONG) 0
  106. };
  107. #else
  108. {
  109.  INITBYTE(OFFSET(Node,         ln_Type),      NT_LIBRARY),
  110.  0x80, (UBYTE) OFFSET(Node,    ln_Name),      (ULONG) &ExLibName[0],
  111.  INITBYTE(OFFSET(Library,      lib_Flags),    LIBF_SUMUSED|LIBF_CHANGED),
  112.  INITWORD(OFFSET(Library,      lib_Version),  VERSION),
  113.  INITWORD(OFFSET(Library,      lib_Revision), REVISION),
  114.  0x80, (UBYTE) OFFSET(Library, lib_IdString), (ULONG) &ExLibID[0],
  115.  (ULONG) 0
  116. };
  117. #endif
  118.  
  119.  
  120. /* ----------------------------------------------------------------------------------------
  121.    ! L_OpenLibs:
  122.    !
  123.    ! Since this one is called by InitLib, libraries not shareable between Processes or
  124.    ! libraries messing with RamLib (deadlock and crash) may not be opened here.
  125.    !
  126.    ! You may bypass this by calling this function fromout LibOpen, but then you will
  127.    ! have to a) protect it by a semaphore and b) make sure, that libraries are only
  128.    ! opened once (when using global library bases).
  129.    ---------------------------------------------------------------------------------------- */
  130.  
  131. ULONG __saveds __stdargs L_OpenLibs(struct AmiStartModuleBase *AmiStartModuleBase)
  132. {
  133.  SysBase = (*((struct ExecBase **) 4));
  134.  
  135.  IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 37);
  136.  if(!IntuitionBase) return(FALSE);
  137.  
  138.  GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 37);
  139.  if(!GfxBase) return(FALSE);
  140.  
  141.  DOSBase = (struct DosBase *) OpenLibrary("dos.library", 37);
  142.  if(!DOSBase) return(FALSE);
  143. /*
  144.  MUIMasterBase = OpenLibrary("muimaster.library", 19);
  145.  if(!MUIMasterBase) return(FALSE);
  146. */
  147.  
  148.  UtilityBase = OpenLibrary("utility.library", 39);
  149.  if(!UtilityBase) return(FALSE);
  150.  
  151.  AmiStartModuleBase->exb_IntuitionBase = IntuitionBase;
  152.  
  153.  AmiStartModuleBase->exb_GfxBase       = GfxBase;
  154.  AmiStartModuleBase->exb_SysBase       = SysBase;
  155.  AmiStartModuleBase->exb_DosBase       = DOSBase;
  156.  //AmiStartModuleBase->exb_MUIMasterBase = MUIMasterBase;
  157.  AmiStartModuleBase->exb_UtilityBase   = UtilityBase;
  158.  
  159.  return(TRUE);
  160. }
  161.  
  162. /* ----------------------------------------------------------------------------------------
  163.    ! L_CloseLibs:
  164.    !
  165.    ! This one by default is called by ExpungeLib, which only can take place once
  166.    ! and thus per definition is single-threaded.
  167.    !
  168.    ! When calling this fromout LibClose instead, you will have to protect it by a
  169.    ! semaphore, since you don't know whether a given CloseLibrary(foobase) may cause a Wait().
  170.    ! Additionally, there should be protection, that a library won't be closed twice.
  171.    ---------------------------------------------------------------------------------------- */
  172.  
  173. void __saveds __stdargs L_CloseLibs(void)
  174. {
  175.  if(GfxBase)       CloseLibrary((struct Library *) GfxBase);
  176.  if(IntuitionBase) CloseLibrary((struct Library *) IntuitionBase);
  177.  if(DOSBase) CloseLibrary((struct Library *) DOSBase);
  178.  //if(MUIMasterBase) CloseLibrary(MUIMasterBase);
  179.  if(UtilityBase) CloseLibrary(UtilityBase);
  180. }
  181.